Array.prototype.MyMap = function (callback, thisArg) {
    if (typeof callback !== 'function') {
        throw new TypeError(callback + ' is not a function');
    }
    
    if (this == undefined) {
        throw new TypeError('this is null or not defined');
    }
  
    const res = [];
    // 同理
    const O = Object(this);
    const len = O.length >>> 0;
    for (let i = 0; i < len; i++) {
        if (i in O) {
            // 调用回调函数并传入新数组
            res[i] = callback.call(thisArg, O[i], i, this);
        }
    }
    return res;
}
const array1 = [1, 4, 9, 16];
const map1 = array1.MyMap(x => x * 2);

console.log(map1);